home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PNL Libraries / MyListManager.p < prev    next >
Encoding:
Text File  |  1995-08-22  |  3.7 KB  |  147 lines  |  [TEXT/CWIE]

  1. unit MyListManager;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Lists;
  7.         
  8.     function LCountSelections (list: ListHandle): integer;
  9.     function LHasSelection (list: ListHandle): boolean;
  10.     procedure LSetSingleSelection (list: ListHandle; v: integer);
  11.     function LPointToCell (list: ListHandle; pt: Point; var c: cell): boolean;
  12.     function LGetFirstSelection (list: ListHandle; var c: cell): boolean;
  13.     function LGetLastSelection (list: ListHandle; var c: cell): boolean;
  14.     function LClickSafe(localPt:Point; modifiers:integer; theList:ListRef):boolean;
  15.  
  16. implementation
  17.  
  18.     uses
  19.         OSUtils, Traps;
  20.         
  21.     function LCountSelections (list: ListHandle): integer;
  22.         var
  23.             c: Cell;
  24.             count: integer;
  25.     begin
  26.         count := 0;
  27.         c.h := 0;
  28.         c.v := 0;
  29.         while LGetSelect(true, c, list) do begin
  30.             count := count + 1;
  31.             c.v := c.v + 1;
  32.         end;
  33.         LCountSelections := count;
  34.     end;
  35.  
  36.     function LHasSelection (list: ListHandle): boolean;
  37.         var
  38.             c: Cell;
  39.     begin
  40.         c.h := 0;
  41.         c.v := 0;
  42.         LHasSelection := LGetSelect(true, c, list);
  43.     end;
  44.  
  45.     procedure LSetSingleSelection (list: ListHandle; v: integer);
  46.         var
  47.             c: Cell;
  48.     begin
  49.         c.h := 0;
  50.         c.v := v;
  51.         LSetSelect(true, c, list);
  52.         c.v := 0;
  53.         c.h := 0;
  54.         while LGetSelect(true, c, list) do begin
  55.             if c.v <> v then begin
  56.                 LSetSelect(false, c, list);
  57.             end;
  58.             c.v := c.v + 1;
  59.             c.h := 0;
  60.         end;
  61.     end;
  62.  
  63.     function LPointToCell (list: ListHandle; pt: Point; var c: cell): boolean;
  64.     begin
  65.         c.h := 0;
  66.         c.v := -1;
  67.         if PtInRect(pt, list^^.rView) then begin
  68.             c.v := list^^.visible.top + (pt.v - list^^.rView.top) div list^^.cellSize.v;
  69.         end;
  70.         LPointToCell := PtInRect(c, list^^.dataBounds);
  71.     end;
  72.  
  73.     function LGetLastSelection (list: ListHandle; var c: cell): boolean;
  74.         var
  75.             tmp: integer;
  76.     begin
  77.         LGetLastSelection := false;
  78.         c.h := 0;
  79.         c.v := 0;
  80.         while LGetSelect(true, c, list) do begin
  81.             LGetLastSelection := true;
  82.             tmp := c.v;
  83.             c.v := c.v + 1;
  84.         end;
  85.         c.v := tmp;
  86.     end;
  87.  
  88.     function LGetFirstSelection (list: ListHandle; var c: cell): boolean;
  89.     begin
  90.         c.h := 0;
  91.         c.v := 0;
  92.         LGetFirstSelection := LGetSelect(true, c, list);
  93.     end;
  94.  
  95. {
  96. ----------------------------------------------------------------------------
  97.     LClickPPCSafe
  98.     
  99.     Process a mouse-down in a list.
  100.     
  101.     Entry:    localPt = click location in local coords.
  102.             modifiers = keyboard modifiers from event record.
  103.             theList = handle to list record.
  104.             
  105.     Exit:    function result = true if double-click.
  106.     
  107.     This function is identical to the standard LClick function, except
  108.     it contains a hack by Dave Radcliffe of Apple DTS to solve a
  109.     problem with clickloop functions in native mode. The problem is
  110.     that the 68K List Manager expects the Boolean function
  111.     result in the Z bit in the condition code register, but the Mixed
  112.     Mode Manager doesn't set this bit correctly. The hack uses a 68K 
  113.     wrapper in native mode to set the Z bit.
  114. ----------------------------------------------------------------------------
  115. }
  116.  
  117.     function LClickSafe(localPt:Point; modifiers:integer; theList:ListRef):boolean;
  118.         var
  119.             clickLoop68K : packed record
  120.                 move:longInt;
  121.                 jsr:integer;
  122.                 tst:integer;
  123.                 rts:integer;
  124.                 clickLoopUPP:ListClickLoopUPP;
  125.             end;
  126.     begin
  127.         if theList^^.lClickLoop = nil then begin
  128.             LClickSafe := LClick(localPt, modifiers, theList);
  129.         end else begin
  130.             clickLoop68K.move := $207A0008;
  131.             clickLoop68K.jsr := $4E90;
  132.             clickLoop68K.tst := $4A00;
  133.             clickLoop68K.jsr := $4E75;
  134.             clickLoop68K.clickLoopUPP := theList^^.lClickLoop;
  135. {$IFC not GENERATINGPOWERPC}
  136.             if NGetTrapAddress(_HWPriv, OSTrap) <> NGetTrapAddress(_Unimplemented, ToolTrap) then begin
  137.                 FlushDataCache;
  138.                 FlushInstructionCache;
  139.             end;
  140. {$ENDC}
  141.             theList^^.lClickLoop := @clickLoop68K;
  142.             LClickSafe := LClick(localPt, modifiers, theList);
  143.             theList^^.lClickLoop := clickLoop68K.clickLoopUPP;
  144.         end;
  145.     end;
  146.     
  147. end.